<%--
  Created by IntelliJ IDEA.
  User: 27244
  Date: 2019/6/18
  Time: 16:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <TITLE>权限管理</TITLE>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <META NAME="Description" CONTENT="Power by hill">
</head>

<body>
<form method="post" name="myform">
    <table border="0" width="300">
        <tr>
            <td width="40%">
                <select style="WIDTH:100%" multiple name="list1" size="12" ondblclick="moveOption(document.myform.list1, document.myform.list2,1)">
                           <c:forEach items="${list1}" var="list1">
                               <c:if test="${list1.id==1}"><option value=1>用户管理</option></c:if>
                               <c:if test="${list1.id==2}"><option value=2>系统管理</option></c:if>
                               <c:if test="${list1.id==3}"><option value=3>角色管理</option></c:if>
                               <c:if test="${list1.id==4}"><option value=4>普通管理员</option></c:if>
                               <c:if test="${list1.id==5}"><option value=5>收藏权限</option></c:if>
                               <c:if test="${list1.id==6}"><option value=6>超管</option></c:if>
                           </c:forEach>
                </select>
            </td>
            <td width="20%" align="center">
                <input type="button" value="添加" onclick="moveOption(document.myform.list1, document.myform.list2,1)"><br/>
                <br/>
                <input type="button" value="删除" onclick="moveOption(document.myform.list2, document.myform.list1,2)">
            </td>
            <td width="40%">
                <select style="WIDTH:100%" multiple name="list2" size="12" ondblclick="moveOption(document.myform.list2, document.myform.list1,2)">
                    <c:forEach items="${list2}" var="list2">
                        <c:if test="${list2.mid==1}"><option value=1>用户管理</option></c:if>
                        <c:if test="${list2.mid==2}"><option value=2>系统管理</option></c:if>
                        <c:if test="${list2.mid==3}"><option value=3>角色管理</option></c:if>
                        <c:if test="${list2.mid==4}"><option value=4>普通管理员</option></c:if>
                        <c:if test="${list2.mid==5}"><option value=5>收藏权限</option></c:if>
                        <c:if test="${list2.mid==6}"><option value=6>超管</option></c:if>

                    </c:forEach>
                </select>
            </td>
            <td>
                <button onclick="changepos(list2,-1)" type="button">上移</button>
                <br/>
                <button onclick="changepos(list2,1)" type="button">下移</button>
            </td>
        </tr>
    </table>
    值：<input type="text" name="city" size="40">
</form>
<script type="text/javascript" src="${base}/statics/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="${base}/statics/js/jquery-1.12.4.js"></script>
<script language="JavaScript">
    <!--
    function moveOption(e1,e2,val) {
        try{
            for(var i=0;i<e1.options.length;i++){
                if(e1.options[i].selected){
                    var e = e1.options[i];
                    e2.options.add(new Option(e.text, e.value));
                    e1.remove(i);

                    if (val == 1){
                        cImg_add(e.value);
                    }else{
                        cImg_del(e.value);
                    }


                    ii=i-1
                }
            }
            document.myform.city.value=getvalue(document.myform.list2);
        }
        catch(e){}
    }

    /**
     * 删除
     * @param obj
     * @param c_id
     */
    function cImg_del(c_id){
        debugger;

        var id =c_id;
        var r=confirm("是否确认删除？");
        if(r==true){
            //确定执行删除
            $.ajax({
                url:"${base}/UserGroup/deleteGm.do?gid=${sessionScope.gid}",
                data:{"mid":id},
                type:'get',
                dataType:'text',
                success:function (data) {
                    if(data=="ok"){
                        alert("删除成功!");
                        //删除成功后，刷新页面信息
                       /* location.reload();*/
                    }else{

                        alert("删除失败!");
                        location.reload();
                    }
                }
            });
        }


    }
    function getvalue(geto){
        var allvalue = "";
        for(var i=0;i<geto.options.length;i++){
            allvalue +=geto.options[i].value + ",";
        }
        return allvalue;
    }
    function changepos(obj,index)
    {
        if(index==-1){
            if (obj.selectedIndex>0){
                obj.options(obj.selectedIndex).swapNode(obj.options(obj.selectedIndex-1))
            }
        }
        else if(index==1){
            if (obj.selectedIndex<obj.options.length-1){
                obj.options(obj.selectedIndex).swapNode(obj.options(obj.selectedIndex+1))
            }
        }
    }
    //-->
    /**
     * 添加
     * @param obj
     * @param c_id
     */
    function cImg_add(c_id){
        var id =c_id;
            $.ajax({
                url: "${base}/UserGroup/addGroupMen.do?gid=${sessionScope.gid}",
                data:{"id":id},
                type:'post',
                dataType:'text',
                success:function (data) {
                    if(data=="ok"){
                        alert("添加成功!");
                        location.reload();
                    }else{

                        alert("添加失败!");
                        location.reload();
                    }
                }
            });
    }
</script>
</body>
</html>
